require "TableDials"
require "DialPanelCtrl"
local transform;
local gameObject;

MenuPanel = {};
local this = MenuPanel
local m_Content
local luaBehaviour

--启动事件--
function MenuPanel.Awake(obj)
	gameObject = obj;
	transform = obj.transform;
	m_Content = obj.transform:Find("ScrollRect/ViewPort/Content")

	this.InitPanel();
	
	luaBehaviour = gameObject:GetComponent('LuaBehaviour');
	logWarn("MenuPanel Awake lua--->>"..gameObject.name);
end

function MenuPanel.Start()
	logWarn("MenuPanel Start")
end

--初始化面板--
function MenuPanel.InitPanel()
	resMgr:LoadPrefab('menu', { 'EnteranceIconPanel' }, this.InitObj);
	
	this.more = transform:Find("Top Screen/More").gameObject
	this.setting = transform:Find("Top Screen/Setting").gameObject
	UIEvent.AddButtonClick(this.more,MoreClick)
	UIEvent.AddButtonClick(this.setting,SettingClick)
end

function MenuPanel.InitObj(objs)
	for i = 1, #TableDials do
		local go = newObject(objs[0])
		go.name = tostring(i)
		go.transform:SetParent(m_Content)
		go.transform.localScale = Vector3.one
		go.transform.localPosition = Vector3.zero
		
		resMgr:LoadSprite('dial_asset.unity3d',{TableDials[i].Icon}, function(imgs)
			go:GetComponent('Image').sprite = imgs[0]
			m_CurrentClickIndex = i
			UIEvent.AddButtonClick(go.gameObject, function()
				local index = i
				log("Click" .. index)
				log(TableDials[index].ID)
				
				local dialCtrl = CtrlManager.GetCtrl(CtrlNames.DialPanel)
				if dialCtrl ~= nil then
					--dialCtrl:Awake(TableDials[index])
					dialCtrl:Awake()
				end
			end)
		end)
	end
end

-- function MenuPanel.IconClick()
	-- log("Click" .. m_CurrentClickIndex)

	
-- end

-- function MenuPanel.ButtonClick(obj)
	-- -- logWarn("Click：" .. obj.name)
	
-- end

function SettingClick()
	logWarn("设置")
end

function MoreClick()
	logWarn("更多内容")
end

--单击事件--
function MenuPanel.OnDestroy()
	logWarn("OnDestroy---->>>");
end

